home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / gnu / amiga / sipp.lha / sipp / demo / conetest.c < prev    next >
C/C++ Source or Header  |  1993-03-13  |  2KB  |  100 lines

  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. #include <sipp.h>
  5. #include <primitives.h>
  6.  
  7.  
  8. #define RESOLUTION 20
  9.  
  10. extern char *optarg;
  11.  
  12. main(argc, argv)
  13.     int    argc;
  14.     char **argv;
  15. {
  16.     FILE      *fp ;
  17.     Object    *cone;
  18.     Object    *trunc_cone;
  19.     Surf_desc   surf;
  20.  
  21.     char    *imfile_name;
  22.     int      mode;
  23.     int      c;
  24.     int      size;
  25.  
  26.     imfile_name = "cone.ppm";
  27.     mode = PHONG;
  28.     size = 256;
  29.  
  30.     while ((c = getopt(argc, argv, "pgfls:")) != EOF) {
  31.         switch (c) {
  32.           case 'p':
  33.             mode = PHONG;
  34.             imfile_name = "cone.ppm";
  35.             break;
  36.  
  37.           case 'g':
  38.             mode = GOURAUD;
  39.             imfile_name = "cone.ppm";
  40.             break;
  41.  
  42.           case 'f':
  43.             mode = FLAT;
  44.             imfile_name = "cone.ppm";
  45.             break;
  46.  
  47.           case 'l':
  48.             mode = LINE;
  49.             imfile_name = "cone.pbm";
  50.             break;
  51.  
  52.           case 's':
  53.             size = atoi(optarg);
  54.             break;
  55.         }
  56.     }
  57.  
  58.     sipp_init();
  59.  
  60.     lightsource_create(1.0, 1.0, 1.0, 0.9, 0.9, 0.9, LIGHT_DIRECTION);
  61.     lightsource_create(-1.0, -1.0, 0.5, 0.4, 0.4, 0.4, LIGHT_DIRECTION);
  62.  
  63.     surf.ambient = 0.5;
  64.     surf.specular = 0.6;
  65.     surf.c3 = 0.2;
  66.     surf.color.red = 1.0000;    /* light salmon */
  67.     surf.color.grn = 0.6275;
  68.     surf.color.blu = 0.4784;
  69.     surf.opacity.red = 1.0;
  70.     surf.opacity.grn = 1.0;
  71.     surf.opacity.blu = 1.0;
  72.  
  73.     /* The ordinary cone */
  74.     cone = sipp_cone(1.0, 0.0, 4.0, RESOLUTION, &surf, basic_shader, WORLD);
  75.     object_move(cone, -3.0, 0.0, 0.0);
  76.     object_add_subobj(sipp_world, cone);
  77.  
  78.     /* The truncated cone */
  79.     trunc_cone = sipp_cone(1.0, 0.4, 5.0, RESOLUTION, &surf, basic_shader,
  80.                            WORLD); 
  81.     object_move(trunc_cone, 3.0, 0.0, 0.0);
  82.     object_add_subobj(sipp_world, trunc_cone);
  83.  
  84.     /* The cylinder (a trucated cone with equal top and bottom radii */
  85.     object_add_subobj(sipp_world, sipp_cylinder(1.0, 3.0, RESOLUTION, &surf,
  86.                                                 basic_shader, WORLD));  
  87.  
  88.     camera_params(sipp_camera, 5.0, -10.0, 6.0,  0.0, 0.0, 0.0,  
  89.                   0.0, 0.0, 1.0,  0.4);
  90.  
  91.     printf("Rendering, wait...");
  92.     fflush(stdout);
  93.  
  94.     fp = fopen(imfile_name, "w");
  95.     render_image_file(size, size, fp, mode, 2);
  96.     printf("Done.\n");
  97.  
  98.     exit(0);
  99. }
  100.